package com.yida.gwj.config.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;

import com.yida.gwj.config.domain.GwjAttachmentInfo;
import com.yida.gwj.config.domain.request.GwjAttachementUploadRequest;
import com.yida.gwj.config.domain.request.GwjAttachmentInfoRequest;
import com.yida.gwj.config.service.IGwjAttachmentInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.yida.common.log.annotation.Log;
import com.yida.common.log.enums.BusinessType;
import com.yida.common.security.annotation.RequiresPermissions;
import com.yida.common.core.web.controller.BaseController;
import com.yida.common.core.web.domain.AjaxResult;
import com.yida.common.core.utils.poi.ExcelUtil;
import com.yida.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 附件信息Controller
 *
 * @author ruoyi
 * @date 2023-04-19
 */
@Api(tags = "附件信息")
@Validated
@RestController
@RequestMapping("/attachInfo")
public class GwjAttachmentInfoController extends BaseController {
    @Autowired
    private IGwjAttachmentInfoService gwjAttachmentInfoService;

    @ApiOperation("查询附件信息列表")
    //@RequiresPermissions("system:info:list")
    @GetMapping("/list")
    public TableDataInfo list(GwjAttachmentInfo gwjAttachmentInfo) {
        startPage();
        List<GwjAttachmentInfo> list = gwjAttachmentInfoService.selectGwjAttachmentInfoList(gwjAttachmentInfo);
        return getDataTable(list);
    }

    @ApiOperation("获取附件信息详细信息")
    //@RequiresPermissions("system:info:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(gwjAttachmentInfoService.selectGwjAttachmentInfoById(id));
    }

    @ApiOperation("新增附件信息")
    //@RequiresPermissions("system:info:add")
    @Log(title = "附件信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Valid GwjAttachmentInfoRequest request) {
        return toAjax(gwjAttachmentInfoService.insertGwjAttachmentInfo(request));
    }

    @ApiOperation("修改附件信息")
    //@RequiresPermissions("system:info:edit")
    @Log(title = "附件信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GwjAttachmentInfo gwjAttachmentInfo) {
        return toAjax(gwjAttachmentInfoService.updateGwjAttachmentInfo(gwjAttachmentInfo));
    }

    @ApiOperation("删除附件信息")
    //@RequiresPermissions("system:info:remove")
    @Log(title = "附件信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(gwjAttachmentInfoService.deleteGwjAttachmentInfoByIds(ids));
    }

    @ApiOperation("接收附件")
    @PutMapping("/receipt")
    @Log(title = "附件信息", businessType = BusinessType.UPDATE)
    public AjaxResult receiptAttachment(@NotEmpty(message = "附件id不能为空") @RequestParam List<Long> ids) {
        return toAjax(gwjAttachmentInfoService.receiptAttachment(ids));
    }

    @ApiOperation("取消接收附件")
    @PutMapping("/cancel")
    @Log(title = "附件信息", businessType = BusinessType.UPDATE)
    public AjaxResult cancelReceipt(@NotEmpty(message = "附件id不能为空") @RequestParam List<Long> ids) {
        return toAjax(gwjAttachmentInfoService.cancelReceipt(ids));
    }

    @ApiOperation("上传附件")
    @Log(title = "附件信息", businessType = BusinessType.INSERT)
    @PostMapping("/upload")
    public AjaxResult upload(@RequestPart @Valid GwjAttachementUploadRequest request, @RequestPart MultipartFile[] files) {
        return toAjax(gwjAttachmentInfoService.upload(request, files));
    }

}
